import { Controller, Get, Post, Body, Patch, Param, Delete, Inject, BadRequestException, Query, ParseIntPipe } from '@nestjs/common';
import { FriendshipService } from './friendship.service';
import { UserId } from '@/common/decorator/param.decorator';
import { FriendAddDto } from './dto/friend-add.dto';
import { FriendListDto } from './dto/friend-list.dto';


@Controller('friendship')
export class FriendshipController {
    @Inject()
    private readonly friendshipService: FriendshipService;
    @Get('list')
    friendship(@UserId() id: number, @Query() friendListDto: FriendListDto) {
        return this.friendshipService.friendship(id, friendListDto)
    }
    // 获取除自己和已添加好友的用户列表
    @Get('list/user')
    usership(@UserId() id: number, @Query() friendListDto: FriendListDto) {
        return this.friendshipService.usership(id, friendListDto)
    }

    @Post('add')
    add(@UserId() userId: number, @Body() friendAddDto: FriendAddDto) {
        return this.friendshipService.add(userId, friendAddDto);
    }
    @Delete('remove/:id')
    remove(@UserId() userId: number, @Param('id', ParseIntPipe) id: number) {
        if (!id) throw new BadRequestException('好友id不能为空')
        return this.friendshipService.remove(userId, id);
    }

    @Get("request_list")
    requestList(@UserId() userId: number) {
        return this.friendshipService.requestList(userId);
    }

    @Get('agree/:id')
    agree(@Param('id') friendId: number, @UserId() userId: number) {
        if (!friendId) throw new BadRequestException('好友id不能为空')
        return this.friendshipService.agree(userId, friendId);
    }
    @Get('reject/:id')
    reject(@Param('id') friendId: number, @UserId() userId: number) {
        if (!friendId) throw new BadRequestException('好友id不能为空')
        return this.friendshipService.reject(userId, friendId);
    }
}
